<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title></title>
		<style type="text/css">
			 .numericInput {
			text-align:right;
		 	}
		</style>
		<%@ include file="/WEB-INF/jsp/include.jsp"%>
			<script type="text/javascript" src="${path }/js/autoNumeric/autoNumeric.js"></script>
		<script type="text/javascript">
		var path = "${path}";
		var params=new Object();
		var url=path+"/dictdata/dmSsflbm/queryPageWithBm";
		
		var numeric_options_bl_2 = {
				aSign: '%',
				pSign: 's',
				vMin: '0',
				vMax: '100'					
		};

		$(function(){
			//设置AjaxLoading
			 $(".numericInput").autoNumeric('init', numeric_options_bl_2);
			setAjaxLoading();
			var grid=$("#tt");
			initGrid(grid);
		});
		
		
		
		//初始化表格和数据
		function initGrid(grid) {
		     var columns=[
			            { field: "id", title: "ID", hidden: true, align: "left", sortable: false, resizable: true, width: 80},		
			            { field: "ssflbm", title: "税收分类编码", align: "left",halign: "center", sortable: false, resizable: true, width: 160 },
			            { field: "spmc", title: "商品名称", align: "left",halign: "center", sortable: false, resizable: true, width: 350 },
			            { field: "ysxm", title: "应税项目", align: "left",halign: "center", sortable: false, resizable: true, width: 185 },
			            { field: "ybZzssl", title: "一般增值税税率", align: "left",halign: "center", sortable: false, resizable: true, width: 295},
			            { field: "jyZzssl", title: "简易增值税税率", align: "left",halign: "center", sortable: false, resizable: true, width: 345}
			        ];
		    initPageGrid(grid, params, url,columns,"#tb");
		    /*var gridOptions = $("#tt").datagrid("options");
			 gridOptions.onDblClickCell= function(index,field,value){
				selectGwf();
		    }; */
		    btnQuery();
		}
		
		function btnQuery(){
			var grid=$("#tt");
			params.ssflbm = $("#bm").val();
			params.spmc = $("#spmc").val();
			params.ysxm = $("#ysxm").val();
			if($("#sl").autoNumeric('get') != null && $("#sl").autoNumeric('get') != ''){
				params.sl = $("#sl").autoNumeric('get')/100;
			}else{
				params.sl = '';
			}
			getPage(grid,params,url);
		}
		
		function btnCz(){
			 $("#bm").val("");
			$("#spmc").val("");
			$("#ysxm").val("");
			$("#sl").val("");
			btnQuery();
		}
		function selectGwf(){
	      //$.messager.confirm("友情提醒", "是否确定设置？", function(b) {
	      $.messager.confirm("问题", "请确认是否要修改？", function (b) {
		   if (b) {
			var rows = $('#tt').datagrid('getSelections');
		    if (rows.length == 0) {
		        $.messager.alert("操作提示", "请先选择！", "info");
		        //$.alert("pick", "info", "");
		        return;
		    }
		    var rowData = rows[0];
		    if("${flag}" == "1"){
			    parent.$("#ssflbm").val(rowData.ssflbm);
			    closeLayer();
		    }else  {
		    	var rowDatas = parent['${windowsName}']. $('#tt').datagrid('getSelections');
		    	var param = new Object();
		    	var urlPath = "";
		    	if("${flag}" == "2"){
			    	var ids = "";
			    	urlPath = "/pj/pjXxfp/updateSsflbm";
			    	$.each(rowDatas,function(i,val){
			    		ids += rowDatas[i].id + ",";
			    	});
			    	param.ids = ids;
		    		
		    	}else if("${flag}" == "3"){
		    		param = parent['${windowsName}'].getParam();
		    		urlPath = "/pj/pjXxfp/updateAllSsflbm";
		    	}
		    	param.ssflId = rowData.id;
		    	$.ajax({
	        		type:"POST",
	       			url:path+urlPath,
	        		data:param,
	       			dataType:"json",
	       			async: true,
	       			success:function callback(data){
	       				var analyMsg = data;
	       				if(analyMsg.code!="0000"){
	         				$.messager.alert('操作提示',analyMsg.msg,'info',function(){});
	       				    //$.alert("update", "error", "");
	         			}else{
	         				if(analyMsg.returnObject.errorCount > 0){
	         					param.ids= analyMsg.returnObject.fpIds;
	         					//$.messager.confirm("友情提醒", analyMsg.returnObject.errorCount + "条发票税率与税收分类编码税率对应税率不一致，是否有差额开票情况，是否继续设置？", function (b) {
	         					$.messager.confirm("问题", analyMsg.returnObject.errorCount + "条发票税率与税收分类编码税率对应税率不一致，是否有差额开票情况，是否继续设置？", function (b) {
	         			            if (b) {
	         			    			$.ajax({
	         				        		type:"POST",
	         				       			url:path+'/pj/pjXxfp/updateSsflbmBjy',
	         				        		data:param,
	         				       			dataType:"json",
	         				       			async: true,
	         				       			success:function callback(data){
	         				       				var analyMsg = data;
	         				       				if(analyMsg.code!="0000"){
	         				         				$.messager.alert('$.alert',analyMsg.msg,'info',function(){});
	         				       				   //$.alert("update", "error", "");
	         				         			}else{
	         				         				$.messager.alert('信息', "修改编码成功！", 'info', function(){
	         				         					parent['${windowsName}'].btnQuery();
	         				         					 closeLayer();
	         				         				});
	         				         				//$.alert("update", "info", "");
	         				        			}
	         				       			}
	         				       		});	
	         			            }else{
	         			            	parent['${windowsName}'].btnQuery();
			         					 closeLayer();
	         			            }
	         			        });		
	         					
	         					//analyMsg.returnObject.errorCount + '条发票税率与税收分类编码对应税率不一致，请重新对应！';
	         				}else{
	         					//$.messager.alert('友情提醒',"编码设置成功",'info',function(){
	         					$.messager.alert('信息', "修改编码成功！", 'info', function() {
		         					parent['${windowsName}'].btnQuery();
		         					 closeLayer();
		         				});
	         				}
	         				
	        			}
	       			}
	       		});	
		     }
		   }
		 });
		}
		
		
		</script>
	</head>

  <body  style="margin:0px; padding:0px;" > 
	<%@ include file="/WEB-INF/jsp/loading.jsp" %>
	<div class="easyui-layout" fit="true" >
		<div region="center" style="padding: 5px;"  border="false">
			<div class="easyui-layout" fit="true"  border="false">
				<div region="center" title="" border="false" noheader="true" style="padding: 5px 0 0 0;">
					<div class="easyui-layout" fit="true"  border="false">
				<div id="divNorth"  region="north" title="" border="true" collapsible="false" noheader="false" style="padding: 5px; height: 74px; background: none repeat scroll 0 0 #EFEFEF;">
			        <table>
			        		<tr>
			        		<td align="right">税收分类编码：</td><td><input id="bm" type="text" style="width:180px" class="query_input"/></td>
			        		<td align="right">商品名称：</td><td><input id="spmc" type="text" style="width: 180px" class="query_input"/></td>
			        		</tr>
			        		<tr>
			        		<td align="right">应税项目：</td><td><input id="ysxm" type="text" style="width: 180px" class="query_input"/></td>
			        		<td align="right">税率：</td><td><input id="sl" type="text" style="width: 180px" class="numericInput query_input"/></td>
			        		<td>
								<input class="search-btn-blue" style="margin-left:0px" type="button" onclick="btnQuery();" value="查询">
								<input class="search-btn-gray" style="margin-left:5px" type="button" onclick="btnCz();" value="重置">
							</td>	
			            </tr>
			        </table>			
				</div> 
				   <div region="center" title="" border="true">
					        <table id="tt" title="" border="false"></table>
					    </div>
				    </div>
			    </div>
			</div>
	    </div>
    </div>
    
    <div id="tb" style="padding: 1px; height: auto; display: none;">
        <div>
        	<a id="btn_removeNode_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" plain="false" onclick="selectGwf()">确定</a>
        </div>
    </div>
    
</body>
</html>
